<template>
  <div
    id="videoCollection"
    v-infinite-scroll="loadMore"
    infinite-scroll-disabled="busy"
    infinite-scroll-distance="0"
    infinite-scroll-immediate-check="false"
  >
    <div class="count" v-if="count != ''">
      共<span>{{ count }}</span
      >个收藏
    </div>
    <table class="table mt_20" ref="capture" v-if="table_data01.length != 0">
      <thead>
        <tr>
          <th>视频内容</th>
          <th>达人</th>
          <th>点赞数</th>
          <th>评论数</th>
          <th>转发数</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item, index) in table_data01" :key="'table' + index">
          <td>
            <div class="box1">
              <img
                :src="item.thumPic"
                class="leftImg"
                v-if="item.isDelete == 0"
              />
              <img
                src="@/assets/meng/hot_video09.png"
                class="leftImg"
                v-if="item.isDelete == 1"
              />
              <div class="box1Right">
                <p
                  class="rightTitle overflowTextWl"
                  :class="{ delColor: item.isDelete == 1 }"
                >
                  <span v-if="item.isDelete == 1">已删除或隐藏</span>
                  {{ item.title }}
                </p>
                <div class="hotWords">
                  <span>热词:</span>
                  <section v-if="item.hotWordLst != null">
                    <p
                      v-for="(item1, index1) in item.hotWordLst.slice(0, 5)"
                      :key="'hw' + index1"
                      :class="{ delWord: item.isDelete == 1 }"
                    >
                      {{ item1.name }}
                    </p>
                  </section>
                </div>
                <div class="rightText">
                  <span>时长:</span>
                  <span :class="{ delColor: item.isDelete == 1 }">{{
                    format_time(item.duration)
                  }}</span>
                </div>
                <div class="rightText">
                  <span>发布时间:</span>
                  <span :class="{ delColor: item.isDelete == 1 }">{{
                    item.releaseTime
                  }}</span>
                </div>
              </div>
            </div>
          </td>
          <td class="td03">
            <p class="dot">{{ item.nickName }}</p>
          </td>

          <td class="td05">
            <img src="@/assets/meng/l.png" />
            <span>{{ format_num(item.favoriteCount) }}</span>
          </td>
          <td class="td06">
            <img src="@/assets/meng/c.png" />
            <span>{{ format_num(item.commentCount) }}</span>
          </td>
          <td class="td07">
            <img src="@/assets/meng/s.png" />
            <span>{{ format_num(item.shareCount) }}</span>
          </td>
          <td class="td08">
            <el-tooltip
              effect="light"
              content="视频详情"
              placement="top"
              popper-class="mytooltip"
              :hide-after="2000"
            >
              <img
                src="@/assets/meng/hot_video01.png"
                @click="
                  dialog = true;
                  active_name01 = '0';
                  video_id = item.awemeId;
                "
              />
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="播放"
              placement="top"
              popper-class="mytooltip"
              :hide-after="2000"
            >
              <a :href="item.url" target="_blank"
                ><img src="@/assets/meng/hot_video03.png"
              /></a>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="取消收藏"
              placement="top"
              popper-class="mytooltip"
              :hide-after="2000"
            >
              <img
                src="@/assets/meng/hot_video05.png"
                @click="cancelStar(item.awemeId, index)"
              />
            </el-tooltip>
          </td>
        </tr>
      </tbody>
    </table>
    <div
      v-loading="loading"
      v-if="!(table_data01.length < (page01 - 1) * 20)"
      class="loading grayLoading"
      element-loading-text="拼命加载中..."
      element-loading-spinner="el-icon-loading"
    ></div>
    <p
      class="nothing"
      v-show="
        table_data01.length != 0 && table_data01.length < (page01 - 1) * 20
      "
    >
      我是有底线的～
    </p>
    <div class="empty addTop" v-show="!loading && table_data01.length == 0">
  <img src="@/assets/liu/zw.png" />
      <p>您还未收藏任何内容哦~</p>
    </div>
    <pop v-if="dialog" v-model="dialog" :id="video_id" :index="active_name01" />
  </div>
</template>
<script>
import html2canvas from "html2canvas";
import pop from "@/pages/meng/video/pop";
export default {
  name: "videoCollection",
  components: { pop },
  data() {
    return {
      dialog: false,
      video_id: "",
      active_name01: "1",
      //   以上是弹出窗
      active_name: "0",
      busy: false,
      loading: true,
      table_data01: [],
      page01: 1,
      cancel01: null,
      cancel: null,
      order_by: "desc", //   表格头部排序
      sort: "favoriteCount", //   表格头部排序
      count: "",
    };
  },
  computed: {},
  created() {
    this.get_data();
  },
  mounted() {},
  methods: {
    get_data() {
      let that = this;
      this.loading = true;
      this.busy = true;
      this.$axios
        .get(
          "/api/collection/GetAwemeCollection",
          {
            params: {
              pageIndex: this.page01,
              pageSize: 20,
            },
          },
          {
            cancelToken: new that.$axios.CancelToken(function executor(c) {
              if (that.cancel01) that.cancel01();
              that.cancel01 = c;
            }),
          }
        )
        .then((response) => {
          if (response.data.code == 0) {
            // console.log(response.data.data);
            this.page01 += 1;

            this.table_data01 = this.table_data01.concat(response.data.data);
            that.count = response.data.count;
            response.data.data.length < 20
              ? (this.busy = true)
              : (this.busy = false);
          }
          this.loading = false;
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 取消收藏
    cancelStar(id, index) {
      let that = this;
      that.$axios
        .post(
          "/api/collection/CancelCollection",
          {
            CollectId: id,
            Module: 2, //模块 1达人 2视频 3音乐 4话题 5商品
          },
          {
            cancelToken: new that.$axios.CancelToken(function executor(c) {
              if (that.cancel != null) {
                that.cancel();
              }
              that.cancel = c;
            }),
          }
        )
        .then((res) => {
          if (res.data.code == 0) {
            that.table_data01.splice(index, 1);
            that.count--;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    loadMore: function () {
      if (this.page01 == 31) {
        return false;
      }
      this.get_data();
    },
  },
};
</script>

<style scoped lang='less'>
#videoCollection {
  background: #f1f1f1;
  img {
    outline: none;
  }
}
.addTop {
  margin-top: 150px;
}
.count {
  padding-top: 20px;
  color: #888;
  font-size: 14px;
  span {
    color: #fd7f2c;
    font-family: DINAlternate-Bold;
  }
}
table {
  width: 100%;
  background-color: #fff;
  thead {
    img {
      width: 5px;
      height: 10px;
      vertical-align: 0;
      margin-right: 2px;
      cursor: pointer;
    }
    th:nth-of-type(1) {
      text-align: left;
      padding-left: 28px;
    }
  }
  tbody {
    tr {
      .td08 {
        width: 14.2%;
        > img:last-child {
          margin-right: 0;
        }
        img {
          cursor: pointer;
          width: 32px;
          height: 32px;
          margin-right: 12px;
        }
      }
      .td05,
      .td06,
      .td07 {
        width: 7.8%;
        font-family: DINAlternate-Bold;
        img {
          width: 16px;
          margin-right: 3px;
          vertical-align: -2px;
        }
      }
      .td03 {
        color: #1779ff !important;
        > p {
          margin: 0 auto;
          width: 168px !important;
        }
      }
      .td04 {
        width: 9.5%;
      }
      .td03,
      .td04 {
        width: 9.5%;
        font-size: 14px;
        color: #222222;
      }
      .box1 {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        .leftImg {
          width: 80px;
          height: 116px;
          background-color: #fd7f2c;
          border-radius: 4px;
          margin-left: 28px;
          margin-right: 22px;
          border: 1px solid #e5e5e5;
        }
        .box1Right {
          flex: 1;
          text-align: left;
          .rightTitle {
            box-sizing: border-box;
            font-size: 16px;
            color: #222222;
            font-weight: 600;
            span {
              display: inline-block;
              width: 100px;
              height: 26px;
              background-color: #f5f5f5;
              border-radius: 4px;
              border: solid 1px #e5e5e5;
              font-size: 14px;
              color: #888888;
              text-align: center;
              line-height: 26px;
            }
          }
          .hotWords {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            flex-wrap: wrap;
            margin-top: 12px;
            span {
              font-size: 14px;
              color: #888888;
              padding-right: 12px;
              white-space: nowrap;
            }
            section {
              display: inline-block;
              p {
                display: inline-block;
                box-sizing: border-box;
                height: 26px;
                line-height: 26px;
                background-color: #f5f9ff;
                border-radius: 13px;
                border: solid 1px #1779ff;
                font-size: 14px;
                color: #1779ff;
                padding: 0 12px;
                margin-right: 10px;
                overflow: hidden;
                white-space: nowrap;
                margin-bottom: 4px;
              }
            }
          }
          .rightText {
            padding-top: 8px;
            span:nth-child(1) {
              font-size: 14px;
              color: #888888;
              padding-right: 9px;
            }
            span:nth-child(2) {
              font-size: 16px;
              color: #222;
              font-weight: 600;
            }
          }
        }
      }
      .td01 {
        font-family: DINAlternate-Bold;
        // min-width: 50px;
        width: 5.7%;
        // max-width: 95px;
      }
      td {
        height: 176px;
        text-align: center;
      }
    }
  }
}
#videoCollection {
  height: fit-content;
  min-height: 100vh;
}
</style>